/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2012 Gary Paluk, http://www.plugin.io
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

package io.plugin.blib.gui.widgets 
{
	import io.plugin.blib.gfx.BlibContentAlignment;
	import io.plugin.blib.gfx.BlibFont;
	/**
	 * ...
	 * @author Gary Paluk - http://www.plugin.io
	 */
	public class BlibLabel extends BlibContainer 
	{
		
		private var _font: BlibFont;
		private var _text: String;
		private var _alignment: int;
		
		//TODO make a default font
		
		public function BlibLabel( font: BlibFont ) 
		{
			super();
			super.focusable = false;
			width = 200;
			_text = "Label";
			_font = font;
			_alignment = BlibContentAlignment.TOP_LEFT;			
		}
		
		public function get font():BlibFont 
		{
			return _font;
		}
		
		public function set font(value:BlibFont):void 
		{
			_font = value;
		}
		
		public function get alignment():int 
		{
			return _alignment;
		}
		
		public function set alignment(value:int):void 
		{
			_alignment = value;
		}
		
		public function get text():String 
		{
			return _text;
		}
		
		public function set text(value:String):void 
		{
			_text = value;
		}
		
		protected function drawText(): void
		{
			switch( _alignment )
			{
				case BlibContentAlignment.TOP_LEFT :
					_font.print( text, tint, absoluteX, absoluteY, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.TOP_CENTER :
					_font.print( text, tint, absoluteX + width / 2, absoluteY, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.TOP_RIGHT :
					_font.print( text, tint, absoluteX + width, absoluteY, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.MIDDLE_RIGHT :
					_font.print( text, tint, absoluteX + width, absoluteY + height / 2, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.MIDDLE_CENTER :
					_font.print( text, tint, absoluteX + width / 2, absoluteY + height / 2, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.MIDDLE_LEFT :
					_font.print( text, tint, absoluteX + width / 2, absoluteY, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.BOTTOM_RIGHT :
					_font.print( text, tint, absoluteX + width, absoluteY + height, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.BOTTOM_CENTER :
					_font.print( text, tint, absoluteX + width / 2, absoluteY + height, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
				case BlibContentAlignment.BOTTOM_LEFT :
					_font.print( text, tint, absoluteX, absoluteY + height, alignment, width, height, rotation, scaleX, scaleY, hotspot );
				break;
			}
		}
		
		override public function draw():void 
		{
			
			if ( visible )
			{
				super.draw();
				drawText();
			}
			
		}
		
	}

}